var app = getApp()

// list.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        wait:null,
        finish:null,
        cancel:null,
        userInfo: {},
        imgUrls: [
            '../../images/theme3.jpg',
            '../../images/swiper2.png'
        ],
        mode: 'aspectFill',
        src:'../../images/theme1.jpg',
        indicatorDots: false,
        autoplay: true,
        interval: 3000,
        duration: 1000
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this

        app.getUserInfo(function (userInfo) {
            that.setData({
                userInfo:userInfo
            })
            wx.request({
                url:"https://wxapps.lovemojito.com/mApp/getList.php",
                data: {
                    openid:userInfo.openId,
                    jyj:'jyj'
                },
                header: {
                    'content-type': 'application/json'
                },
                success: function(res) {
                    if(res.data.wait == null){
                        res.data.wait = [];
                    }
                    if(res.data.finish == null){
                        res.data.finish = [];
                    }
                    if(res.data.cancel == null){
                        res.data.cancel = [];
                    }
                    that.setData({
                        wait:res.data.wait,
                        finish:res.data.finish,
                        cancel:res.data.cancel
                    })
                }
            })

        })
    },

    /**
     * 下拉刷新
     */
    onPullDownRefresh: function(){
        var that = this
        app.getUserInfo(function (userInfo) {
            that.setData({
                userInfo:userInfo
            })
            wx.request({
                url:"https://wxapps.lovemojito.com/mApp/getList.php",
                data: {
                    openid:userInfo.openId,
                    jyj:'jyj'
                },
                header: {
                    'content-type': 'application/json'
                },
                success: function(res) {
                    console.log(res);
                    if(res.data.wait == null){
                        res.data.wait = [];
                    }
                    if(res.data.finish == null){
                        res.data.finish = [];
                    }
                    if(res.data.cancel == null){
                        res.data.cancel = [];
                    }
                    that.setData({
                        wait:res.data.wait,
                        finish:res.data.finish,
                        cancel:res.data.cancel
                    })
                    wx.stopPullDownRefresh()
                },
                error:function () {
                    wx.stopPullDownRefresh()
                }
            })

        })
    }
})